
/*
 * @Author: Dannycjh 2233879049@qq.com
 * @Date: 2023-04-15 09:30:32
 * @LastEditors: Dannycjh 2233879049@qq.com
 * @LastEditTime: 2023-04-26 20:39:00
 * @FilePath: \cc-game-development-template\assets\scripts\common\Common.ts
 */
export class Matrix {
    private _isValid: boolean = false;
    private _name: string = '';
    constructor() {
        this._isValid = true;
        this._name = Object.prototype.constructor.name;
    }

    public get name(): string { return this._name; }

    public init(...args: any[]) {
        var _len: number = args.length;
        switch (_len) {
            case 0: this.onInit(); break;
            case 1: this.onInit(args[0]); break;
            case 2: this.onInit(args[0], args[1]); break;
            case 3: this.onInit(args[0], args[1], args[2]); break;
            case 4: this.onInit(args[0], args[1], args[2], args[3]); break;
            case 5: this.onInit(args[0], args[1], args[2], args[3], args[4]); break;
            default: break;
        }
    }

    public destroy() {
        this._isValid = false;
        this.onDestroy();
        let self = this;
        self = null;
    }

    public get isValid(): boolean { return this._isValid; }

    protected onInit(...param: any[]) {
        // 子类实现
    }

    protected onDestroy() {
        // 子类实现
    }
}



/** 
 * 单例基类
 *  */
export class Singleton<T> extends Matrix {
    private static instance: any = null;
    public static getInstance<T>(c: { new(): T }): T {
        if (this.instance == null) {
            this.instance = new c();
        }
        return this.instance;
    }

    public static destroyInstance<T>(c: { new(): T }): void {
        if (this.instance) {
            this.instance = null;
        }
    }

    public Update(dt: number) {

    }

}

/**
 * 本地读写目录
 */
export const localKey = {
    CHANGE_LANGUAGE: "ChangeLanguage",//改变语言


    AUDIO: 'local_audio',//
    LOGIN: 'local_login',
    SET: 'local_set',
    USER: 'local_user',
    LANG: 'local_language',
    WRITE_DIR: 'native_write_path', // 本地写目录，热更使用

    EFFECT_SW: 'local_effectsw', // 音效
    MUSIC_SW: 'local_musicsw', // 音乐
    NOTICE_ID: 'local_noticeId', // 公告Id
    
}

/**
 * 派发事件目录
 */
export const EventConst = {
    CHANGE_LANGUAGE: "ChangeLanguage",//改变语言
    LOAD_HOME: "loadHome",//进入首页
    AUDIOPLAY: "AudioPlay",//播放音效
    UPLOAD_DATA: "UploadData",//上传游戏数据
    RECOVER_GAME: "RecoverGame",//上传游戏数据
    UPDATA_USERINFO: "updata_userinfo",//用户信息更新

    //大厅事件
    UPDATE_COIN: "UPDATE_COIN", // 更新金币数
    UPDATE_STARCOIN: "UPDATE_STARCOIN", // 更新星币数
    UPDATE_MODE1_BALL: "UPDATE_MODE1_BALL", // 更新下注球的信息
    UPDATE_MODE1_STATUS_CHANGE: "UPDATE_MODE1_STATUS_CHANGE", // 幸运球状态发生变化
    UPDATE_MODE1_BET: "UPDATE_MODE1_BET", // 幸运球下注回调
    UPDATE_WITHDRAW_JL: "UPDATE_WITHDRAW_JL", //更新兑换记录消息
    UPDATE_SET_NICK: "UPDATE_SET_NICK", //更新昵称
    UPDATE_SET_HEAD: "UPDATE_SET_HEAD", //更换头像
    UPDATE_TASK_HD: "UPDATE_TASK_HD", //任务红点
    UPDATE_CUE_DETAIL: "UPDATE_CUE_DETAIL", //球杆详情

    // 多人台球和四轮台球事件（大厅）
    ROOM_LIST_REFRESH : "ROOM_LIST_REFRESH", // 刷新房间列表
    ROOM_INFO_UPDATE : "ROOM_INFO_UPDATE", // 房间信息更新
    ROOM_DESTROY : "ROOM_DESTROY", // 房间销毁
    ROOM_KICK_OUT : "ROOM_KICK_OUT", // 踢出房间

    BLOOD_MATCH_CUC : "BLOOD_MATCH_CUC", // 匹配成功通知(血流模式)

    //游戏内事件
    BALL_IN_ROLE : "BALL_IN_ROLE", // 球进洞事件
    BALL_IN_ROLE_SCORE : "BALL_IN_ROLE_SCORE", // 球进洞得分事件
    WHITEBALL_CONTACT_BALL : "WHITEBALL_CONTACT_BALL", // 白球的碰球事件
    POS_WHITE_BALL : "POS_WHITE_BALL", // 摆白球阶段
    POS_WHITE_BALL_END : "POS_WHITE_BALL_END", // 摆白球结束
    GAME_CUE_END : "GAME_CUE_END", // 球杆操作完毕事件
    ALLBALL_SLEEP : "ALLBALL_SLEEP", // 所有球停止事件
    ACTION_TIME_END : "ACTION_TIME_END",  // 操作时间倒计时到了
    ACTION_BALL_POINT : "ACTION_BALL_POINT",  // 调整击球作用点
    GAME_ABEL_BALL : "GAME_ABEL_BALL",  // 通知球体上的呼吸效果显示隐藏
    GAME_HIT_ACTIONVIEW : "GAME_HIT_ACTIONVIEW",  // 关闭作用点界面


    
}


export interface AudioVol {
    music: number,
    effect: number,
}

export class Constant {
    
    public static EnemyPlaneType = {
        TYPE1: 1,
        TYPE2: 2,
    }

    public static Combination = {
        PLANE1: 1,
        PLANE2: 2,
        PLANE3: 3,
    }

    public static CollistionType = {
        SELF_PLAN: 1 << 1,
        ENEMY_PLAN: 1 << 2,
        SELF_BULLET: 1 << 3,
        ENEMY_BULLET: 1 << 4,
        BULLET_PROP: 1 << 5,
    }

    public static BulletPropType = {
        BULLET_M: 1,//火箭
        BULLET_H: 2,//磁铁
        BULLET_S: 3//护盾
    }

    public static Direction = {
        LEFT: 1,
        MIDDLE: 2,
        RIGHT: 3
    }

}